import Schema from 'async-validator';
import {Message} from 'element-ui';
const descriptor = {
	data: {
		type: 'array',
		defaultField: [{
			type: 'object',
			require: true,
			fields: {
				voidList: {
					type: 'array',
					require: true,
					defaultField: [{
						type: 'object',
						require: true,
						fields: {
							name: {
								type: 'string',
								required: true,
								message: '请选择文件'
							},
							versionNumber: {
								type: 'string',
								required: true,
								message: '请选择版本号'
							},
							qty: {
								type: 'string',
								required: true,
								message: '请输入作废数量'
							},
							voidDate: {
								type: 'string',
								required: true,
								message: '请选择作废日期'
							},
							dealType: {
								type: 'number',
								required: true,
								message:'请选择作废文件处理',
							},
							voidRetentionPeriod: {
								type: 'number',
								message:'请选择原件作废保留期限',
							},
							applyDeptId: {
								type: 'string',
								required: true,
								message: '请选择申请部门'
							},
							applyUserId: {
								type: 'string',
								required: true,
								message: '请选择申请人'
							}
						}
					}]
				},
				number: {
					type: 'string',
					required: true,
					message: '请补充生产编号',
				},

				jiluFilesIds: {
					type: 'string',
					required: true,
					message: '请添加记录文件',
				},
				retentionPeriod: [{
					type: 'string',
					required: true,
					message: '请输入记录保留期限'
				}, {
					validator: (rule, value) => value >= '2',
					message: '记录保留期限应≥2年'
				}]
			}
		}]
	}
}
const validator = new Schema(descriptor);
export const validateFun = (list,callBack) => {
	validator.validate({
		data: list
	}).then(() => {
		callBack()
	}).catch(({
		errors
	}) => {
		if (errors) {
			Message.error(errors[0].message);
		}
	})
}
